package com.lam.common.components.easyexcel.export.iterator;

import java.util.Iterator;
import java.util.List;

import com.lam.common.utils.CollectionUtil;

public abstract class SimpleDataIterator<T> extends AbstractDataIterator<T> {
	
	protected List<String> idList;
	protected List<List<String>> batchList;
	protected Iterator<List<String>> batchListIterator;
	
	protected int pageSize = 5000; 
	/** 当前已处理的总条数 */
	protected long curTotalCount = 0; 
	/** 当前文件已处理的总条件 */
	protected long curFileRowCount = 0; 
	
	protected void setIdList(List<String> idList) {
		setIdList(idList, pageSize);
	}
	
	protected void setIdList(List<String> idList, int pageSize) {
		this.pageSize = pageSize;
		this.idList = idList;
		batchList = CollectionUtil.list2BatchList(idList, pageSize);
		batchListIterator = batchList.iterator();
	}
	
	protected long curFileRowCountAdd(long rowCount) {
		if(curFileRowCount >= getFileMaxRowCount()) {
			setFileNoAdd();
			curFileRowCount = 0;
		}
		this.curTotalCount += rowCount;
		this.curFileRowCount += rowCount;
		return this.curFileRowCount;
	}
	
	protected List<String> nextBatchIdList() {
		return batchListIterator.next();
	}
	
	@Override
	public boolean hasNext() {
		return batchListIterator != null && batchListIterator.hasNext();
	}
	
	@Override
	public long totalCount() {
		return idList == null ? 0 : idList.size();
	}
	
	@Override
	public int fileCount() {
		return batchList == null ? 0 : batchList.size();
	}
	
	public long getCurTotalCount() {
		return curTotalCount;
	}
	
	public long getCurFileRowCount() {
		return curFileRowCount;
	}

	public List<String> getIdList() {
		return idList;
	}

	public List<List<String>> getBatchList() {
		return batchList;
	}

	public Iterator<List<String>> getBatchListIterator() {
		return batchListIterator;
	}

	public int getPageSize() {
		return pageSize;
	}

}
